BASE_PROJECT_FOLDER=${HOME}/temp/yapai
PROJECT_INFO_FOLDER=${HOME}/shell/com/yapai/project
PROJECTS=($@)
if [[ ${#PROJECTS[@]} -lt 1 ]]
then
  echo "You don't give me project , I'll deploy all project with my whole power"
  PROJECTS=$(ls -1 ${PROJECT_INFO_FOLDER})
fi
excludes=(nanshan-api servicecenter syn)
for pro in ${PROJECTS[@]}
do
  if [[ "${excludes[@]}" =~ "$pro" ]]
  then
    continue
  fi
  branches=$(cat ${PROJECT_INFO_FOLDER}/${pro} | jq -r '.unit_branches[]' 2>/dev/null)
  git_info=$(cat ${PROJECT_INFO_FOLDER}/${pro} | jq -r '.git_path' 2>/dev/null)
  project_name=${git_info##*/}
  project_name=${project_name%%.git}
  if [[ -z $branches ]]
  then
    branches=("\$keep\$")
  fi
  for bran in ${branches[@]}
  do
    if [[ -d ${BASE_PROJECT_FOLDER}/${project_name} ]]
    then
      cd ${BASE_PROJECT_FOLDER}/${project_name}
      if [[ "\$keep\$" != "$bran" ]]
      then
        git checkout $bran
      fi
      deploy -e185 -i install -u upload -Pzxhtom -Dyplicdis -ktrue -p$pro -ctrue
      sleep 3
    fi
  done
done
